import { createRouter, createWebHashHistory } from "vue-router";
import { useFileStore } from "../Views/Files/files";
const routes = [
    {
        name: "files",
        path: "/files",
        component: () => import("../Views/Files.vue"),
    },
    {
        name: "editor",
        path: "/editor/:id",
        props: true,
        beforeEnter: (to: any, from: any, next: any) => {
            const openID = to.params.id;
            const store = useFileStore();
            if (store.openingFile && store.openingFile.id === openID) {
                console.log("直接打开文件");
                next();
            } else {
                store.openFile(openID).then(next);
            }
        },
        component: () => import("../components/index.vue"),
    },
    {
        name: "test",
        path: "/test",
        component: () => import("../Views/Test/index.vue"),
    },
    { path: "/:pathMatch(.*)*", redirect: { name: "files" } },
];
const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

export default router;
